/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nus.util;

import java.util.Properties;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

/**
 *
 * @author T W Ong
 */
public class EmailUtil {
    
   private String from;
   private String password;
   private String to;
   private String subject;
   private String body;
   private String host;   
   private Properties properties;
   
   public EmailUtil(String from, String to, String host)
   {
       this.from = from;
       this.from = to;
       this.host = host;
   }
   
   public String email() 
   {
      String ret = "SUCCESS";
      properties = new Properties();
      properties.setProperty("mail.smtp.host", host);
      Session session = Session.getDefaultInstance(properties);
      try
      {
         Message message = new MimeMessage(session);
         message.setFrom(new InternetAddress(from));
         message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
         message.setSubject(subject);
         message.setText(body);
         Transport.send(message);
      }
      catch(Exception e)
      {
         ret = "ERROR";
         e.printStackTrace();
      }
      return ret;
   }

   public String getFrom() {
      return from;
   }

   public void setFrom(String from) {
      this.from = from;
   }

   public String getTo() {
      return to;
   }

   public void setTo(String to) {
      this.to = to;
   }

   public String getSubject() {
      return subject;
   }

   public void setSubject(String subject) {
      this.subject = subject;
   }

   public String getBody() {
      return body;
   }

   public void setBody(String body) {
      this.body = body;
   }

    
    
    
}
